package com.test.io;

import java.nio.ByteBuffer;
import java.nio.channels.Pipe;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class PipeDemo {
    public static void main(String[] args) throws Exception{
        Pipe pipe = Pipe.open();
        Pipe.SinkChannel sinkChannel = pipe.sink();
        String newData = "new Data to be writer ";
        ByteBuffer buffer = ByteBuffer.allocate(48);
        buffer.clear();
        buffer.put(newData.getBytes());
        buffer.flip();
        while (buffer.hasRemaining()){
            sinkChannel.write(buffer);
        }

        Lock lock = new ReentrantLock();
    }

    public static void sourceP() throws  Exception {
        Pipe pipe = Pipe.open();
        Pipe.SourceChannel sourceChannel = pipe.source();
        ByteBuffer buffer = ByteBuffer.allocate(48);
        int byteRead =  sourceChannel.read(buffer);
    }
}
